import { ReqPage, ResPage } from "_common/DataType";
import { IotDevice, IotFacility } from "_common/entity";
import { createRequest, RequestMethod } from "_common/request";
import { AxiosInstance } from "axios";

/**
 * 设施管理
 */
export class ApiFacility {
  /**
   * @description 请求实例
   * @type {RequestMethod}
   * @memberof ApiDevice
   * */
  request: RequestMethod;
  url: string = "api/iot/facility";

  /**
   * @description 构造函数
   * @param config axios 配置
   */
  public constructor(instance: AxiosInstance) {
    // axios 实例化
    this.request = createRequest(instance);
  }

  /** 创建 */
  create(data: any) {
    return this.request.post<boolean>(this.url + "", data);
  }

  /** 更新 */
  update(data: any) {
    return this.request.put<boolean>(this.url + "", data);
  }

  /** 删除 */
  delete(id: number) {
    return this.request.delete<boolean>(this.url + "/" + id);
  }

  /** 获取设备列表 */
  getList() {
    return this.request.get<IotFacility[]>(this.url + "/get-list");
  }

  /**
   * 获取分页列表
   * @param params
   * @returns
   */
  getPage(params: ReqPage) {
    return this.request.get<ResPage<IotFacility>>(
      this.url + "/get-page",
      params
    );
  }

  /** 获取站点-设施 树结构 */
  getTree() {
    return this.request.get<any[]>(this.url + "/get-tree", {});
  }

  // 获取设施下面的设备
  getFacilityDevice(facilityId: number) {
    return this.request.get<IotDevice[]>(
      this.url + "/get-facility-device/" + facilityId,
      {}
    );
  }

  // 更新设计json
  updateDesignJson(data: any) {
    return this.request.post<boolean>(this.url + "/update-designer", data);
  }

  // 获取设计json
  getDesignJson(facilityId: number) {
    return this.request.get<any>(this.url + "/get-designer/" + facilityId, {});
  }
}
